package com.solomon.travel.common.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.solomon.travel.common.custom.mapper.ScenicCustomMapper;
import com.solomon.travel.common.mapper.ProtocalMapper;
import com.solomon.travel.common.mapper.ScenicMapper;
import com.solomon.travel.common.model.Page;
import com.solomon.travel.common.po.Protocal;
import com.solomon.travel.common.po.Scenic;
import com.solomon.travel.common.po.ScenicExample;
import com.solomon.travel.common.service.ScenicService;

@Service
public class ScenicServiceImpl implements ScenicService {
	
	@Resource
	private ScenicMapper scenicMapper;
	
	@Resource
	private ScenicCustomMapper scenicCustomMapper;
	
	@Resource
	private ProtocalMapper protocalMapper;

	@Override
	public int add(Scenic scenic) {
		return scenicMapper.insertSelective(scenic);
	}

	@Override
	public int update(Scenic scenic) {
		return scenicMapper.updateByPrimaryKeySelective(scenic);
	}

	@Override
	public Scenic getById(String objectId) {
		return scenicMapper.selectByPrimaryKey(objectId);
	}

	@Override
	public Scenic getByUser(String userId) {
		ScenicExample example = new ScenicExample();
		example.createCriteria().andUserIdEqualTo(userId);
		List<Scenic> scenics = scenicMapper.selectByExample(example);
		if (!scenics.isEmpty()) {
			return scenics.get(0);
		}
		return null;
	}

	@Override
	public int add(Protocal protocal) {
		return protocalMapper.insertSelective(protocal);
	}

	@Override
	public int update(Protocal protocal) {
		return protocalMapper.updateByPrimaryKeySelective(protocal);
	}

	@Override
	public Integer countBySerch(Scenic scenic) {
		return scenicCustomMapper.countBySerch(scenic);
	}

	@Override
	public List<Scenic> listBySerch(Scenic scenic, Page page) {
		return scenicCustomMapper.listBySerch(scenic, page);
	}

}
